package com.kfm.am;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class Test {

    public static void main(String[] args) throws Exception {

//        Properties prop = new Properties();
//        prop.load(new FileInputStream("io\\test.properties"));
//        System.out.println(prop.get("username"));
//        System.out.println(prop.get("password"));
        // 连接池 getConnection()
//        Class.forName("com.mysql.cj.jdbc.Driver");
//        String url = "jdbc:mysql://localhost:3306/kfm";
//        Connection conn = DriverManager.getConnection(url, "root", "");
//        PreparedStatement preparedStatement = conn.prepareStatement("select * from s_emp");
//        ResultSet resultSet = preparedStatement.executeQuery();
//        while (resultSet.next()) {
//            System.out.println(resultSet.getObject("last_name"));
//        }
        Properties prop = new Properties();
        prop.load(new FileInputStream("io\\datasource.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
        Connection connection = dataSource.getConnection();
        System.out.println(connection);
        PreparedStatement preparedStatement = connection.prepareStatement("select * from s_emp");
        ResultSet resultSet = preparedStatement.executeQuery();
        while (resultSet.next()) {
            System.out.println(resultSet.getObject("last_name"));
        }


    }
}
